import { createStore, Store, useStore as useVuexStore } from 'vuex'

import { IRootState, IStoreType } from './types'

import loginModule from './login/login'

import mainModule from './main/main'
import systemModule from './main/system/system'

const store = createStore<IRootState>({
  state: () => {
    return {
      name: 'coderwhy'
    }
  },
  mutations: {},
  getters: {},
  actions: {},
  modules: {
    loginModule,
    mainModule,
    systemModule
  }
})

export function setupStore() {
  store.dispatch('loginModule/loadLocalLogin')
  store.dispatch('mainModule/refreshSetHistoryPage')
}
export function useStore(): Store<IStoreType> {
  return useVuexStore()
}

export default store
